package com.auz.datagenerator.launcher;

import java.util.Hashtable;

import com.auz.datagenerator.connector.AbstractConnector;
import com.auz.datagenerator.connector.Type;
import com.auz.datagenerator.connector.TypeHandler;
import com.auz.datagenerator.connector.heuristiclink.Parser;
import com.auz.datagenerator.connector.heuristiclink.ValueHeuristicLink;
import com.auz.datagenerator.heuristics.time.IIntervalHeuristic;
import com.auz.datagenerator.heuristics.time.SetIntervalHeuristic;
import com.auz.datagenerator.heuristics.value.BaseValueHeuristic;
import com.auz.datagenerator.heuristics.value.IValueHeuristic;
import com.auz.datagenerator.heuristics.value.MomentumValueHeuristic;
import com.auz.datagenerator.heuristics.value.PeriodicityValueHeuristic;
import com.auz.datagenerator.heuristics.value.StrengthValueHeuristic;
import com.auz.datagenerator.heuristics.value.TrendValueHeuristic;
import com.auz.datagenerator.publishing.FilePublisher;
import com.auz.datagenerator.publishing.IPublisher;
import com.auz.datagenerator.publishing.tcpip.Server;

/**
 * Example launcher for a heuristic based system generating random double values 
 * with standard market-like characteristics.
 * @author Aurelien Bonnel
 */
public class Launcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Create the heuristics
		// Instrument base value of 100
		BaseValueHeuristic base = new BaseValueHeuristic(100);
		// Momentum heuristic based on this base value
		MomentumValueHeuristic m = new MomentumValueHeuristic(base.getValue());
		// A strength heuristic also based on the base value
		StrengthValueHeuristic s = new StrengthValueHeuristic(base.getValue());
		// Periodicity
		PeriodicityValueHeuristic p = new PeriodicityValueHeuristic(base.getValue());
		// Trend
		TrendValueHeuristic t = new TrendValueHeuristic(base.getValue());
		
		// Add all the heuristics to a map and assign to each an identifier
		Hashtable<String, IValueHeuristic> map = new Hashtable<String, IValueHeuristic>();
		map.put("momentum", m);
		map.put("strength", s);
		map.put("periodicity", p);
		map.put("trend", t);
		map.put("base", base); 
		
		// Create a heuristic link for this mapping
		ValueHeuristicLink link = new ValueHeuristicLink(map);
		// Set an equation setting how the individual heuristics produce one and only value
		link.setEquation("$base$+$strength$*($trend$)*($momentum$+$periodicity$)");
		// Create a publisher; in this case a server
		IPublisher publisher = new FilePublisher("../published.txt");
		// Create a timer
		IIntervalHeuristic timer = new SetIntervalHeuristic(1000);
		
		TypeHandler handler = new TypeHandler(Type.NUMBER);
		// Connect the value heuristic link to the timer and the publisher
		AbstractConnector c = new AbstractConnector(timer, link, publisher, handler);
		// Run
		c.run();
	}

}
